package com.dgty.dg_common.util

import android.content.res.Resources

/**
 * Title: Extension.kt
 * Description:
 * Created DateTime: 2023-02-08
 * Created by xxl.
 */
object Extension {
    fun Number.px2dp(): Float {
        val f = toFloat()
        val scale: Float = Resources.getSystem().displayMetrics.density
        return (f / scale + 0.5f)
    }

    fun Number.dp2px(): Int {
        val f = toFloat()
        val scale: Float = Resources.getSystem().displayMetrics.density
        return (f * scale + 0.5f).toInt()
    }

    fun Number.toEnglishMonth(): String {
        return when(toInt()) {
            1 -> "January"
            2 -> "February"
            3 -> "March"
            4 -> "April"
            5 -> "May"
            6 -> "June"
            7 -> "July"
            8 -> "August"
            9 -> "September"
            10 -> "October"
            11 -> "November"
            12 -> "December"
            else -> ""
        }
    }

    fun Number.addZero(): String {
        if (toInt() < 10) {
            return "0" + toInt()
        }

        return toString()
    }
}